package com.rbcs.base.project.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.MatchMode;
import org.springframework.stereotype.Service;

import com.rbcs.base.model.Project;
import com.systop.core.service.BaseGenericsManager;

@Service
public class ProjectManager extends BaseGenericsManager<Project> {

	/**
	 * 检查当前所选择的项目是否有项目负责人
	 * @return
	 */
	public String checkProjectManager(Integer projectId) {
		String projectManagers = StringUtils.EMPTY;
		if (projectId != null) {
			Project project = getDao().get(Project.class, projectId);
			if (StringUtils.isBlank(project.getManagerIds())) {
				return project.getName();
			}
		}
    return projectManagers;
	}
	
	/**
	 * 根据当前登录用户获取其所在的所有项目集合
	 * @param loginUserId
	 * @return
	 */
	public List<Project> getGroupProjects(Integer loginUserId) {
		String hql = "from Project p where p.managerIds like ? or p.memberIds like ? ";
		List<Project> groupProjects = query(hql, new Object[] {
				MatchMode.ANYWHERE.toMatchString(loginUserId.toString()), 
				MatchMode.ANYWHERE.toMatchString(loginUserId.toString())});
		return groupProjects;
	}
}
